#region Imported Namespaces
using System;
using System.Collections.Specialized;
using System.Data;
using System.Web.UI.WebControls;

using PHSRAG.Insight21.Context;
using BO = PHSRAG.Insight21.BusinessObjects;
using DataAccess = PHSRAG.Utility.DataAccess;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
using GenerateKey = PHSRAG.Insight21.BusinessObjects.ModuleKey;
#endregion

namespace PHSRAG.Insight21.SearchContext
{
	#region Class PersonnelSearchContext
	/// <summary>
	/// The PersonnelSearchContext class encapsulates the search context associated with the PersonnelSearch control.
	//  this control is used for Personnel Summary and Salary Grid Pages
	/// </summary>
	public class PersonnelSearchContext : SearchContext
	{
		#region Constants
		private static string PersonnelSearchContextKey = GenerateKey.MakeKey("PersonnelSearchContext_44076BEC-93AD-4eb0-9D7C-F79A2EDD410B",GenerateKey.Personnel);
		#endregion

		#region Private Types
		/// <summary>
		/// The DataTableIndex enumeration defines the index of each table (which holds data pertaining to the set of
		/// drop-down-lists) within the data container.
		/// </summary>
		private enum DataTableIndex
		{
			Status, HRDepartment, PayFrequencyType, FiscalYear, Max
		}
		#endregion

		#region Constructor
		/// <summary>
		/// Create an instance of the PersonnelSearchContext class. Since this object does not hold any state (other than
		/// whatever the base class holds), there is nothing to initialize.
		/// </summary>
		/// <param name="cachePolicy">Cache policy to use</param>
		public PersonnelSearchContext(ICachePolicy cachePolicy)	: base(cachePolicy)
		{
		}
		#endregion

		#region Public Properties
		/// <summary>
		/// Get the key to be used in all caching operations for this instance of the object.
		/// </summary>
		public static string CacheKey	{ get { return PersonnelSearchContextKey; } }

		
		/// <summary>
		/// Get the data table from the data container which contains data for the status drop-down-list.
		/// </summary>
		public DataTable StatusData
		{
			get { return DataContainer.Tables[(int)DataTableIndex.Status]; }
		}

		/// <summary>
		/// Get the data table from the data container which contains data for the HR_Departments drop-down-list.
		/// </summary>
		public DataTable HRDepartmentData
		{
			get { return DataContainer.Tables[(int)DataTableIndex.HRDepartment]; }
		}

		/// <summary>
		/// Get the data table from the data container which contains data for the Pay Frequency Type drop-down-list.
		/// </summary>
		public DataTable PayFrequencyTypeData
		{
			get { return DataContainer.Tables[(int)DataTableIndex.PayFrequencyType]; }
		}
		/// <summary>
		///  Get the data table from the data container which contains data for the Fiscal year drop-down list.
		/// </summary>
		public DataTable FiscalYearData
		{
			get {return DataContainer.Tables[(int)DataTableIndex.FiscalYear];}
		}
		#endregion

		#region BusinessObject Methods
		/// <summary>
		/// Cache this instance of the PersonnelSearchContext object using the current cache policy.
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(CacheKey, this);
		}

		/// <summary>
		/// Load personnel search data into the data container. The loading is done by invoking a stored procedure.
		/// </summary>
		/// <param name="connectionString">Connection string to the database</param>
		/// <param name="args">Arugments to the invoked stored procedure</param>
		public override void Load(string connectionString, params object[] args)
		{
			UserContext userContext = CachePolicy.GetCachedObject(UserContext.CacheKey) as UserContext;
			System.Diagnostics.Trace.Assert(userContext != null);

			DataContainer = DataAccess.GetDataSet(connectionString, "GetPersonnelSearchData",
				DataAccess.BuildSqlParameterArray("@domainUserID", SqlDbType.Int, userContext.DomainUserId));
		}

		/// <summary>
		/// Remove this instance of the PersonnelSearchContext object from the cache using the current cache policy.
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(CacheKey);
		}
		#endregion

		#region SearchContext Members
		/// <summary>
		/// Reset the internal search state.
		/// </summary>
		public override void Reset(string pageName)
		{
		}
		#endregion
	}
	#endregion
}

// --- EOF --- 